﻿using EF.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EF.Controllers
{
    public class CustomerController : Controller
    {
        EShopV10 db = new EShopV10();

        public ActionResult Index()
        {
            var model = new Customer();

            ViewBag.Customers = db.Customers;

            return View(model);
        }

        public ActionResult Insert(Customer model)
        {
            db.Customers.Add(model);
            db.SaveChanges();

            return RedirectToAction("Index");
        }

        public ActionResult Edit(String Id)
        {
            ViewBag.Customers = db.Customers;

            var model = db.Customers.Find(Id);

            return View("Index", model);
        }

        public ActionResult Update(Customer model)
        {
            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();

            return RedirectToAction("Index");
        }

        public ActionResult Delete(String Id)
        {
            var entity = db.Customers.Find(Id);
            db.Customers.Remove(entity);
            db.SaveChanges();

            return RedirectToAction("Index");
        }
	}
}